//
//  GroupNoticeTableViewCell.m
//  Findif
//
//  Created by Mac on 2019/2/25.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "GroupNoticeTableViewCell.h"

@interface GroupNoticeTableViewCell ()

@property (nonatomic, weak)UIView * backView;
@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UILabel * timeLabel;
@property (nonatomic, weak)UIView * lineView;
@property (nonatomic, weak)UILabel * subLabel;


@end

@implementation GroupNoticeTableViewCell


- (void)setModel:(NoticeModel *)model{
    
    _model = model;
    
    self.titleLabel.text = model.notice_title;
    self.timeLabel.text = model.notice_inputtime;
    
    CGFloat bottom = self.lineView.bottom + 7 * SCREENH6;
    NSString * content = model.notice_content;
    
    if (content) {
        
        self.subLabel.text = content;
        CGSize attrStrSize = [self preferredSizeWithMaxWidth:325 * SCREENH6 withLabel:self.subLabel];
        CGFloat labH = attrStrSize.height;
        
        self.subLabel.frame = CGRectMake(self.lineView.left, bottom, attrStrSize.width, labH);
        
        bottom = self.subLabel.bottom + 5 * SCREENH6;
    }
    
    self.backView.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 345 * SCREENH6, bottom);
    
    _model.rowHeight = self.backView.bottom + 10 * SCREENH6;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = ColorWithRGB(0xF4F5F6);
    
    
    UIView * backView = [UIView new];
    
    backView.backgroundColor  =ZRWhiteColor;
    backView.layer.cornerRadius = 5 * SCREENH6;
    backView.layer.masksToBounds = YES;
    backView.userInteractionEnabled = YES;
    
    self.backView = backView;
    
    [self.contentView addSubview:self.backView];
    
    
    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * SCREENH6, 10 * SCREENH6, 300 * SCREENH6, 16 * SCREENH6)];
    
    titleLabel.text = @"元旦聚会费用详情";
    titleLabel.textColor = ColorWithRGB(0xFF5C5C);
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.backView addSubview:self.titleLabel];
    
    
    UILabel * timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * SCREENH6, self.titleLabel.bottom + 5 * SCREENH6,300 * SCREENH6, 14 * SCREENH6)];
    
    timeLabel.text = @"2018年9月12日";
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.timeLabel = timeLabel;
    
    [self.backView addSubview:self.timeLabel];
    
    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(10 * SCREENH6, self.timeLabel.bottom + 5 * SCREENH6,315 * SCREENH6, 1 * SCREENH6)];
    
    lineView.backgroundColor = ColorWithRGB(0xe4e4e4);
    
    self.lineView = lineView;
    
    [self.backView addSubview:self.lineView];
    
    
    UILabel * subLabel = [UILabel new];
    
    subLabel.text = @"对你的社员说些什么吧对你的社员说些什么吧对你的社员说些什么吧对你的社员说些什么吧对你的社员说些什么吧对你的社员说些什么吧";
    subLabel.textColor = ZRBlackColor;
    subLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    subLabel.numberOfLines = 0;
    
    self.subLabel = subLabel;
    
    [self.backView addSubview:self.subLabel];
 
}

//- (void)layoutSubviews{
//    
//    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.centerX.mas_equalTo(self.contentView);
//        make.width.mas_equalTo(345 * SCREENH6);
//        make.height.mas_equalTo(130 * SCREENH6);
//    }];
//    
//    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.backView).mas_equalTo(10 * SCREENH6);
//        make.top.mas_equalTo(self.backView).mas_equalTo(10 * SCREENH6);
//    }];
//    
//    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.titleLabel);
//        make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_equalTo(5 * SCREENH6);
//    }];
//    
//    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.backView).mas_equalTo(10 * SCREENH6);
//        make.trailing.mas_equalTo(self.backView).mas_equalTo(-10 * SCREENH6);
//        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10 * SCREENH6);
//        make.height.mas_equalTo(1 * SCREENH6);
//    }];
//    
//    [self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.trailing.mas_equalTo(self.lineView);
//        make.top.mas_equalTo(self.lineView.mas_bottom).offset(5 * SCREENH6);
//    }];
//}

- (CGSize)preferredSizeWithMaxWidth:(CGFloat)maxWidth withLabel:(UILabel *)label
{
    
    CGSize size = [label sizeThatFits:CGSizeMake(maxWidth, 10000000.0f)];
    size.width = fmin(size.width, maxWidth); //在numberOfLine为1模式下返回的可能会比maxWidth大，所以这里我们限制下
    return size;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
